package com.kaifamiao.month04.day21.homework;

import java.util.Objects;

public class Phoenix implements Comparable<Phoenix> {

    private int age;
    private String name;
    private char gender;

    public Phoenix(int age, String name, char gender) {
        this.age = age;
        this.name = name;
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Phoenix phoenix = (Phoenix) o;
        return age == phoenix.age && gender == phoenix.gender && Objects.equals(name, phoenix.name);
    }


    @Override
    public String toString() {
        return "Phoenix" + "{ name:" + this.name + " ,age:" + this.age + " ,gender: " + this.gender + "}";
    }

    @Override
    public int compareTo(Phoenix o) {
        return this.getAge() - ((Phoenix) o).getAge();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int code = 1;
        /*
         * 对象的hashcode =  code * prime + 属性的 hashcode 值。
         * 属性的 hashcode 值， 基本数据类型的值就是其 hash 值
         *  引用数据类型的 hash 值通过其 hashCode 方法计算
         */
        code = code * prime + age;
        code = code * prime + gender;
        code = code * prime + (name == null ? 0 : name.hashCode());
        return code;
    }
}
